const http = require('http');
const url = require('url');

const responseData = {
    id: 1,
    name: 'John',
    age: 30,
}

function toHTML(data) {
    return `
    <ul>
    <li><span>id</span> <span>${data.id}</span></li>
    </ul>
    `
}

const server = http.createServer((req, res) => {
    const { pathname } = url.parse(req.url)
    if (pathname === '/') {
        // 前端想要的类型
        res.writeHead(200, { 'content-type': 'text/html' }) // 告诉浏览器返回的内容的类型
        res.end('<h1>hello</h1>')
    } else {
        res.writeHead(404, { 'content-type': 'text/html' })
        res.end('<h1>not found</h1>')
    }
})

server.listen(3000, () => {
    console.log('Server is running at http://localhost:3000');
});